package com.xuecheng.content.handler;

import com.xuecheng.base.result.CodeErrorResponse;
import com.xuecheng.content.exception.CourseHasChildTeachPlanException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description 全局异常处理器
 * @author 勾新杰
 * @version 1.0
 * @date 2025/1/4 17:49
 */
@Slf4j
@RestControllerAdvice
public class ContentExceptionHandler {

    /**
     * 处理自定义异常
     *
     * @param e 处理自定义异常
     * @return 错误信息
     */
    @ExceptionHandler(CourseHasChildTeachPlanException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CodeErrorResponse handleException(CourseHasChildTeachPlanException e) {
        log.error("系统异常:{}", e.getMessage());
        return new CodeErrorResponse("120409", e.getMessage());
    }
}
